package cc.mrbird.plan.controller;

import cc.mrbird.assets.domain.AssetMana;
import cc.mrbird.common.annotation.Log;
import cc.mrbird.common.controller.BaseController;
import cc.mrbird.common.domain.ResponseBo;
import cc.mrbird.plan.domain.Inspection;
import cc.mrbird.plan.domain.Rehearse;
import cc.mrbird.plan.service.InspectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(description = "巡检信息管理接口")
@Controller
public class InspectionController extends BaseController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

   @Autowired
   private InspectionService inspectionService;

    @ApiOperation(value = "查询巡查点信息")
    @Log("查询巡查点信息")
    @RequestMapping(value = "inspection/findAllPoint",method = RequestMethod.GET)
    @ResponseBody
    public ResponseBo findAllPoint() {
        try {
            List<AssetMana>  assetManaList = this.inspectionService.findAllPoint();
            return ResponseBo.ok(assetManaList);
        } catch (Exception e) {
            log.error("查询巡查点信息失败", e);
            return ResponseBo.error("查询巡查点信息失败，请联系网站管理员！");
        }
    }
    @ApiOperation(value = "新增巡查点信息")
    @Log("新增巡查点信息")
   /* @RequiresPermissions("inspection:add")*/
    @RequestMapping(value = "inspection/add" ,method = RequestMethod.POST)
    @ResponseBody
    public ResponseBo addInspection(Inspection inspection, Integer[] assetManas) {
        try {
            this.inspectionService.add(inspection, assetManas);
            return ResponseBo.ok("新增巡查点信息成功！");
        } catch (Exception e) {
            log.error("新增巡查点信息失败", e);
            return ResponseBo.error("新增巡查点信息失败，请联系网站管理员！");
        }
    }
    @ApiOperation(value = "修改巡查点信息")
    @Log("修改巡查点信息")
  /*  @RequiresPermissions("inspection:update")*/
    @RequestMapping(value = "inspection/update",method = RequestMethod.POST)
    @ResponseBody
    public ResponseBo updateInspection(Inspection inspection, Integer[] assetmanas) {
        try {
            this.inspectionService.updateInspection(inspection, assetmanas);
            return ResponseBo.ok("修改巡查点信息成功！");
        } catch (Exception e) {
            log.error("修改巡查点信息失败", e);
            return ResponseBo.error("修改巡查点信息失败，请联系网站管理员！");
        }
    }
    @ApiOperation(value = "删除巡查点信息")
    @Log("删除巡查点信息")
   /* @RequiresPermissions("inspection:delete")*/
    @RequestMapping(value = "inspection/delete",method = RequestMethod.GET)
    @ResponseBody
    public ResponseBo deleteInspections(String ids) {
        try {
            this.inspectionService.deleteInspections(ids);
            return ResponseBo.ok("删除巡查点信息成功！");
        } catch (Exception e) {
            log.error("删除巡查点信息失败", e);
            return ResponseBo.error("删除巡查点信息失败，请联系网站管理员！");
        }
    }

}
